Add a function to determine the text direction
authorMatthias Clasen <mclasen@redhat.com>
Tue, 10 Dec 2013 21:27:24 +0000 (16:27 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 10 Dec 2013 22:34:23 +0000 (17:34 -0500)
This function can be used in the rare cases where the locale
has to be changed after gtk_init(). Based on a patch
by Jehan <jehan@girinstud.io>.

https://bugzilla.gnome.org/show_bug.cgi?id=720096

docs/reference/gtk/gtk3-sections.txt
gtk/gtkmain.c
gtk/gtkmain.h

index 8a69badb46c329ab28e2053c5ce685be68455fe7..c4a734524d18eccb86907701ad0ca8406cda2db8 100644 (file)
@@ -5715,6 +5715,7 @@ gtk_window_group_get_type
 <TITLE>General</TITLE>
 gtk_disable_setlocale
 gtk_get_default_language
+gtk_get_locale_direction
 gtk_parse_args
 gtk_init
 gtk_init_check
index eba38ccf4e462a715b12b2a089ecde93a8138f32..bbf13701e6020eeca74d7b681ab6372955d547d0 100644 (file)
@@ -696,18 +696,7 @@ do_post_parse_initialization (int    *argc,
   if (debug_flags & GTK_DEBUG_UPDATES)
     gdk_window_set_debug_updates (TRUE);
 
-  {
-  /* Translate to default:RTL if you want your widgets
-   * to be RTL, otherwise translate to default:LTR.
-   * Do *not* translate it to "predefinito:LTR", if it
-   * it isn't default:LTR or default:RTL it will not work 
-   */
-    char *e = _("default:LTR");
-    if (strcmp (e, "default:RTL")==0) 
-      gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
-    else if (strcmp (e, "default:LTR"))
-      g_warning ("Whoever translated default:LTR did so wrongly.\n");
-  }
+  gtk_widget_set_default_direction (gtk_get_locale_direction ());
 
   _gtk_ensure_resources ();
 
@@ -1113,6 +1102,54 @@ gtk_init_check_abi_check (int *argc, char ***argv, int num_checks, size_t sizeof
 
 #endif
 
+/**
+ * gtk_get_locale_direction:
+ *
+ * Get the direction of the current locale. This is the expected
+ * reading direction for text and UI.
+ *
+ * This function depends on the current locale being set with
+ * setlocale() and will default to setting the %GTK_TEXT_DIR_LTR
+ * direction otherwise. %GTK_TEXT_DIR_NONE will never be returned.
+ *
+ * GTK+ sets the default text direction according to the locale
+ * during gtk_init(), and you should normally use
+ * gtk_widget_get_direction() or gtk_widget_get_default_direction()
+ * to obtain the current direcion.
+ *
+ * This function is only needed rare cases when the locale is
+ * changed after GTK+ has already been initialized. In this case,
+ * you can use it to update the default text direction as follows:
+ *
+ * |[
+ * setlocale (LC_ALL, new_locale);
+ * direction = gtk_get_locale_direction ();
+ * gtk_widget_set_default_direction (direction);
+ * ]|
+ *
+ * Returns: the #GtkTextDirection of the current locale
+ *
+ * Since: 3.12
+ */
+GtkTextDirection
+gtk_get_locale_direction (void)
+{
+  gchar            *e   = _("default:LTR");
+  GtkTextDirection  dir = GTK_TEXT_DIR_LTR;
+
+  /* Translate to default:RTL if you want your widgets
+   * to be RTL, otherwise translate to default:LTR.
+   * Do *not* translate it to "predefinito:LTR", if it
+   * it isn't default:LTR or default:RTL it will not work
+   */
+  if (g_strcmp0 (e, "default:RTL") == 0)
+    dir = GTK_TEXT_DIR_RTL;
+  else if (g_strcmp0 (e, "default:LTR") != 0)
+    g_warning ("Whoever translated default:LTR did so wrongly. Defaulting to LTR.\n");
+
+  return dir;
+}
+
 /**
  * gtk_get_default_language:
  *
index 75f3fbc1f1ced39a69950426e613635f7a4fb2bd..38665a59b7c03c037469703d36f7d49fa7b97ad4 100644 (file)
@@ -143,9 +143,16 @@ GDK_AVAILABLE_IN_ALL
 void           gtk_disable_setlocale    (void);
 GDK_AVAILABLE_IN_ALL
 PangoLanguage *gtk_get_default_language (void);
+GDK_AVAILABLE_IN_3_12
+GtkTextDirection gtk_get_locale_direction (void);
 GDK_AVAILABLE_IN_ALL
 gboolean       gtk_events_pending       (void);
 
+#ifndef GTK_DISABLE_DEPRECATED
+void     gtk_exit                 (gint    error_code);
+gchar *        gtk_set_locale           (void);
+#endif /* GTK_DISABLE_DEPRECATED */
+
 GDK_AVAILABLE_IN_ALL
 void       gtk_main_do_event       (GdkEvent           *event);
 GDK_AVAILABLE_IN_ALL